package org.company.earth.concurrent;

import org.company.earth.service.ITaskService;

/**
 * 同步执行程序
 * @author hucw
 *
 */
public class SynchronizedTask implements ITaskService{
    
    private Integer count;
    
    public SynchronizedTask() {
        this.count = 0;
    }
    
    public void syncRun() throws InterruptedException {
        System.out.println("I will in");
        synchronized (count) {
            System.out.println("I'm in");
            Thread.sleep(1000*10);
            count++;
            System.out.println("I will leave");
        }
    }
    
    @Override
    public void execute() {
        try {
            this.syncRun();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
